#include <sys/socket.h>
#include <sys/un.h>
#include <pthread.h>
#include <stdint.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <stdint.h>
#include <sys/socket.h>
#include <cutils/sockets.h>
#include <binder/Parcel.h>
#include <cutils/jstring.h>
#include <assert.h>
#include <cutils/properties.h>
#include <signal.h>

#include <binder/IServiceManager.h>
#include "SQRService.h"


//#ifndef LOG_TAG
#define LOG_TAG "sqr_service"
//#endif

#include <cutils/log.h>

namespace android {
	enum {
		SQUARE = IBinder::FIRST_CALL_TRANSACTION,
	};

	int SQRService::instantiate()
	{
		ALOGE("SQRService instantiate...");   
		int ret = defaultServiceManager()->addService(String16("com.aspros.sqr"), new SQRService());
		ALOGE("SQRService ret = %d \n", ret);
		return ret;
	}

	SQRService::SQRService()
	{
		ALOGV("SQRService created");
	}

	SQRService::~SQRService()
	{
		ALOGV("SQRService destroyed"); 
	}

	status_t SQRService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
	{
		switch (code)
		{
			case SQUARE:{
				int num = data.readInt32();
				reply->writeInt32(num*num); // 平方运算
				ALOGE("onTransact::CREATE_NUM.. num = %d \n", num);
				return NO_ERROR;
			}
			break;

			default:
				ALOGE("onTransact::default\n");
				return BBinder::onTransact(code, data, reply, flags);  
		}
	}

}
